package com.sun.weekend.util;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.sun.weekend.base.Constants;
import com.sun.weekend.beans.BundleBean;
import com.sun.weekend.ui.activity.ModuleActivity;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * @author sunleilei
 */

public class Go2Util {

    public static void go2Module(Context context, BundleBean bean) {
        Intent intent = new Intent(context, ModuleActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constants.BUNDLE_BEAN,bean);
        intent.putExtras(bundle);
        intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void startDetailActivity(Context context,BundleBean bean) {
        try {
            String name = context.getPackageName()+".ui.activity."+bean.getSign()+"Activity";
            Class clazz = Class.forName(name);
            if (clazz != null) {
                Intent intent = new Intent(context, clazz);
                Bundle bundle = new Bundle();
                bundle.putSerializable(Constants.BUNDLE_BEAN,bean);
                intent.putExtras(bundle);
                intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void goLogin(Context mContext) {
        BundleBean bean = new BundleBean();
        bean.setSign("RegisterAndLogin");
        startDetailActivity(mContext,bean);
    }
}
